<template>
	<view>
		<van-card
		  v-for="item in list"
		  :key="item.id"
		  :num="item.goods_number"
		  :price="item.goods_price"
		  :title="item.goods_name"
		  :thumb="item.goods_small_logo"
		  :thumb-link="'/pages/xiang/xiang?id='+item.goods_id"
		/>
		<view class="daodi" v-show="flag">
			到底了
		</view>
	</view>
</template>

<script>
	import qs from "querystring"
	import http from "@/http/http.js"
	export default {
		data() {
			return {
				query:{
					cid:0,
					pagenum:1,
					pagesize:10
				},
					list:[],
					total:0,
					flag:false
				}
		},
		methods: {
			async daya(){
				var str=qs.stringify(this.query)
				let{data:res}= await http.get('https://api-hmugo-web.itheima.net/api/public/v1/goods/search?'+str)
				this.list=[...this.list,...res.message.goods]
				this.total=res.message.total
			},
			// xiang(id){
			// 	wx.navigateTo({url:'pages/xiang/xaing?id'+id})
			// }
		},
		onLoad(optison) {
			this.query.cid=optison.cid
			this.daya()
		},
		onReachBottom(){
			if(this.total>this.list.length){
				this.query.pagenum+=1
				this.daya()
			}else{
				this.flag=true
			}
			
		}
	}
</script>

<style>
.daodi{
	text-align: center;
	background-color: #0000ff;
	color: #ffffff;
}
</style>
